<html>

    <script>
            var   pays={};
         function aliPay(){
            var w=null;
            var that=this;
            var url='http://demo.dcloud.net.cn/payment/?payid=alipay';
            // 支付
            var appid=plus.runtime.appid;
	          if(navigator.userAgent.indexOf('StreamApp')>=0){
		          appid='Stream';
	          }
	          url+='&appid='+appid+'&total=1'
            w=plus.nativeUI.showWaiting();
            var xhr=new XMLHttpRequest();
            xhr.onreadystatechange=function(){
		          switch(xhr.readyState){
			          case 4:
			            w.close();w=null;
			            if(xhr.status==200){
				            console.log('----- 请求订单成功 -----');
				            console.log(xhr.responseText);
				            var order=xhr.responseText;
				            plus.payment.request(that.pays['alipay'],order,function(result){
					          console.log('----- 支付成功 -----');
					          console.log(JSON.stringify(result));
					          plus.nativeUI.alert('支付成功：感谢你的支持，我们会继续努力完善产品。',function(){
						            back();
					            },'捐赠');
				            },function(e){
					            console.log('----- 支付失败 -----');
					            console.log('['+e.code+']：'+e.message);
					            plus.nativeUI.alert('更多错误信息请参考支付(Payment)规范文档：http://www.html5plus.org/#specification#/specification/Payment.html', null, '支付失败：'+e.code);
				            });
			            }else{
				            console.log('----- 请求订单失败 -----');
				            console.log( xhr.status );
				            plus.nativeUI.alert('获取订单信息失败！', null, '捐赠');
			            }
		              break;
			          default:
			            break;
		          }
            }
    	      xhr.open('GET',url);
	          console.log('请求支付订单：'+url);
	          xhr.send();
        }
    function plusReady() {
      var that = this;
      console.log("输出pays:");
      console.log(that.pays);
      // var pays={};
      // 获取支付通道
      plus.payment.getChannels(function (channels) {
        for (var i in channels) {
          var channel = channels[i];
          if (channel.id == 'qhpay' || channel.id == 'qihoo') { // 过滤掉不支持的支付通道：暂不支持360相关支付
            continue;
          }
           console.log(channel.id);
           console.log(channel);
          that.pays[channel.id] = channel;
          }
      }, function (e) {
        console.log('获取支付通道失败：'+e.message);
      });
    }
    </script>
</html>